﻿/**
 * ...
 * @author aboutwhat
 */

package bloom.compiler;
import bloom.error.Error;

class TargetConstants 
{
    public static inline var NEKO = "neko";
    public static inline var CPP = "cpp";
    public static inline var SWF = "swf";
    public static inline var PHP = "php";
    public static inline var JS = "js";
    
    public static inline var DEFAULT_SWF_VERSION = 10;
}

enum Target 
{
    Neko;
    Cpp;
    Php;
    Swf (version : Int);
    Js;
}

private typedef CS = TargetConstants;

class TargetTools 
{
    public static function stringToEnum (str, ?version = CS.DEFAULT_SWF_VERSION) 
    {
        return 
            switch (str) 
            {
                case CS.NEKO : Target.Neko;
                case CS.PHP : Target.Php;
                case CS.SWF : Target.Swf(version);
                case CS.CPP : Target.Cpp;
                case CS.JS : Target.Js;
                default : throw new Error("Invalid Compiler Target (" + str + ")");
            }
    }
    
    public static function enumToString (t:Target) 
    {
        return 
            switch (t) 
            {
                case Neko: CS.NEKO;
                case Php : CS.PHP;
                case Swf(v) : CS.SWF;
                case Js : CS.JS;
                case Cpp : CS.CPP;
            }
    }
    public static function swfVersion (t : Target) : Int 
    {
        return 
            switch (t) 
            {
                case Swf(v) : return v;
                default : throw new Error("This is not a Swf Target (" + enumToString(t) + ")");
            }
    }
}
